function figDhaqtool_CreateFcn(fig, e)
%DHAQTOOL_CREATEFCN Summary of this function goes here
%   Detailed explanation goes here

setappdata(fig, 'State', 'IsCreating');
IniFile= getappdata(fig, 'IniFile');
[dhaqtool_dir, ~, ~] = fileparts(IniFile);
setappdata(fig, 'RootDirectory', [dhaqtool_dir filesep]);

set(fig, 'menu', 'none');

%Registrate Pligin files
[PluginFiles PluginCount] = plugins_ReadFcn( dhaqtool_dir );
setappdata(fig, 'PluginFiles', PluginFiles);
setappdata(fig, 'PluginCount', PluginCount);

figDhaqtool_VidOpenFcn(fig, e );

uigridcontainer('v0', ...
    'parent', fig, ...
    'CreateFcn', @gridMainContainer_CreateFcn ...
    );

% Look for PlugIns with menu
PluginFiles= getappdata(fig, 'PluginFiles');
PluginCount= getappdata(fig, 'PluginCount');
[Value_List List_Length]= plugins_ParseFcn(PluginFiles, PluginCount, 'Menu', 'Root', 'Sub', 'Label', 'Callback');
for i= 1:List_Length
    GenerateMenu(Value_List{i, 1}, Value_List{i, 2}, Value_List{i, 3}, Value_List{i, 4})
end

setappdata(fig, 'State', 'IsRunning');

end

function GenerateMenu(Parent, Sub, Label, Callback)
    h_parent= findobj('label', Parent, 'type', 'uimenu');
    if isempty(h_parent)
        h_parent= uimenu('label', Parent);
    end
    if ~isempty(Sub)
        h_sub= findobj('label', Sub, 'type', 'uimenu');
        if isempty(h_sub)
            h_sub= uimenu('label', Sub, 'parent', h_parent);
        end
        h_parent= h_sub;
    end
    h_label= findobj('label', Label, 'type', 'uimenu');
    if isempty(h_label)
        uimenu('label', Label, 'parent', h_parent, 'callback', Callback);
    else
        error('Label is in use');
    end
end

